using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-09-30
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 测试结果
    /// </summary>
    [Verify]
    [Route("review/testresult")]
    [ApiExplorerSettings(GroupName = "business")]
    public class TestResultController : BaseController
    {
        /// <summary>
        /// 测试结果接口
        /// </summary>
        private readonly ITestResultService _TestResultService;

        public TestResultController(ITestResultService TestResultService)
        {
            _TestResultService = TestResultService;
        }

        /// <summary>
        /// 查询测试结果列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "review:testresult:list")]
        public IActionResult QueryTestResult([FromQuery] TestResultQueryDto parm)
        {
            var response = _TestResultService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询测试结果详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "review:testresult:query")]
        public IActionResult GetTestResult(long Id)
        {
            var response = _TestResultService.GetInfo(Id);

            var info = response.Adapt<TestResultDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加测试结果
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "review:testresult:add")]
        [Log(Title = "测试结果", BusinessType = BusinessType.INSERT)]
        public IActionResult AddTestResult([FromBody] TestResultDto parm)
        {
            var modal = parm.Adapt<TestResult>().ToCreate(HttpContext);

            var response = _TestResultService.AddTestResult(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新测试结果
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "review:testresult:edit")]
        [Log(Title = "测试结果", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateTestResult([FromBody] TestResultDto parm)
        {
            var modal = parm.Adapt<TestResult>().ToUpdate(HttpContext);
            var response = _TestResultService.UpdateTestResult(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除测试结果
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "review:testresult:delete")]
        [Log(Title = "测试结果", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteTestResult([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_TestResultService.Delete(idArr));
        }
    }
}